package PL.practica1;

public class Front {
	private String to;
	private String date;
	private String why;
	private String where;
	private String cadena;
	
	public Front() {
		to = "";
		date = "";
		why = "";
		where = "";
		cadena = "";
	}

//	public Front(String cadena) {
//		this.cadena = cadena;
//	}
	
	public String getTo() {
		return to;
	}
	public void setTo(String to) {
		this.to = to;
	}
	
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	
	public String getWhy() {
		return why;
	}
	public void setWhy(String why) {
		this.why = why;
	}
	
	public String getWhere() {
		return where;
	}
	public void setWhere(String where) {
		this.where = where;
	}
	
	public String getCadena() {
		return cadena;
	}
	public void setCadena(String cadena) {
		this.cadena = cadena;
	}


	public void rellenarFront (String texto) {
		setCadena(texto);
		setTo(buscarEtiqueta(getCadena(), "<to>", "</to>"));
		setDate(buscarEtiqueta(getCadena(), "<date>", "</date>"));
		setWhy(buscarEtiqueta(getCadena(), "<why>", "</why>"));
		setWhere(buscarEtiqueta(getCadena(), "<where>", "</where>"));
	}
	
	
	public String buscarEtiqueta (String cadena, String etiquetaIni, String etiquetaFin) {
		
		int ini = cadena.indexOf(etiquetaIni);
		int fin = cadena.indexOf(etiquetaFin);
		
		return cadena.substring(ini, fin).replaceFirst(etiquetaIni, "");
	}
	
	public String translateTo() {
		return "<TR><TD class=\"front\" span style=\"color: red;\">To: </TD>\n<TD><span style=\"color: red;\">"+getTo()+"</TD></TR>";
	}
	
	
	public String translateDate() {
		return "<TR><TD class=\"front\" span style=\"color: D0AB4B;\">When: </TD>\n<TD><span style=\"color: D0AB4B;\">"+getDate()+"</TD></TR>";
	}
	
	
	public String translateWhere() {
		return "<TR><TD class=\"front\" span style=\"color: 42953D;\">Venue: </TD>\n<TD><span style=\"color: 42953D;\">"+getWhere()+"</TD></TR>";
	}
	
	
	public String translateWhy() {
		return "<TR><TD class=\"front\" span style=\"color: 8E953D;\">Occasion: </TD>\n<TD><span style=\"color: 8E953D;\">"+getWhy()+"</TD></TR>";
	}
	
	
}
